package com.lixiaoyao.reggie.common;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

/**
 * 短信发送工具类
 */
public class SMSUtils {


	public static void sendMessage(String phoneNumbers,String param){
		DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "LTAI5t7AmU62WEpGWff4dxUM", "85jqSJncBGL5Y2RNCVVrEAgaslOINI");

		IAcsClient client = new DefaultAcsClient(profile);

		SendSmsRequest request = new SendSmsRequest();
		request.setPhoneNumbers(phoneNumbers);//接收短信的手机号码
		request.setSignName("阿里云短信测试");//短信签名名称
		request.setTemplateCode("SMS_154950909");//短信模板CODE
		request.setTemplateParam("{\"code\":\""+param+"\"}");//短信模板变量对应的实际值

		try {
			SendSmsResponse response = client.getAcsResponse(request);
			System.out.println(new Gson().toJson(response));
		} catch (ServerException e) {
			e.printStackTrace();
		} catch (ClientException e) {
			System.out.println("ErrCode:" + e.getErrCode());
			System.out.println("ErrMsg:" + e.getErrMsg());
			System.out.println("RequestId:" + e.getRequestId());
		}

	}

}
